function parent_id = set_attribute_parent_id ( file_id, objname )
% If the given variable is "/", then we know we are creating a group
% attribute. Otherwise try to open the variable as a dataset.  If that
% fails, then it must be a subgroup.

v = version('-release');
switch(v)
    case { '2006b', '2007a', '2007b', '2008a', '2008b', '2009a' }
	    statbuf=H5G.get_objinfo (file_id, objname,0);
		switch (statbuf.type) 
			case H5ML.get_constant_value('H5G_GROUP')
            	parent_id = H5G.open ( file_id, objname );
		    case H5ML.get_constant_value('H5G_DATASET')
                parent_id=H5D.open(file_id,objname);
		    case H5ML.get_constant_value('H5G_DATATYPE')
                parent_id=H5T.open(file_id,objname);
		    otherwise
				error('HDF5TOOLS:h5attput:unhandledObjectType', ...
				      '%s is not a group, dataset, or datatype.', objname);
		end

    otherwise
        lapl = H5P.create('H5P_LINK_ACCESS');
        parent_id = H5O.open(file_id,objname,lapl);
        H5P.close(lapl);
end